package cn.wx.read.neo4j.service;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.csvreader.CsvReader;

import cn.wx.read.core.entity.ScholarFos;
import cn.wx.read.core.service.ScholarFosService;
import cn.wx.read.neo4j.repository.ComputeRepository;

/**
 * 聚类对应专家数的实时计算
 */
@Service
@Transactional
public class ComputeFieldService {
	
	@Autowired
	private ComputeRepository computeRepository;
	
	@Autowired
	private ScholarFosService scholarFosService;
	
	/**
	 * 检索需要计算的领域
	 * 开启定时器
	 * 每一分钟 查看 线程池还有有没执行的线程
	 */
	/*@Scheduled(cron="0 0/1 *  * * ? ") 
	public void scheduledFieldCompute() {
		
		
	}*/
	
	/**
	 * 聚类读取csv
	 */
	public void modifyFieldByReadCsv() {
		
		final String filePath = "D:\\my_read_csv\\field_expert_count.csv";
		
		try {
			
			CsvReader csvReader = new CsvReader(filePath);
			
			ScholarFos fos = null;
			// 读表头
            csvReader.readHeaders();
            while (csvReader.readRecord()){
                // 读一整行
            	String line = csvReader.getRawRecord();
				if(StringUtils.isBlank(line)) {
					continue;
				}

				fos = new ScholarFos();
				/**
				 * 解析csv
				 */
				String fId = csvReader.get(0);
				String ecount = csvReader.get(1);
				System.out.println(Long.valueOf(fId) + " : " + Integer.parseInt(ecount));
				fos.setpId(Long.valueOf(fId));
				fos.setScholarNum(Integer.parseInt(ecount));
				scholarFosService.update(fos);
            }

            /**
			 * 关闭读入流
			 */
			csvReader.close();
			csvReader = null;
            
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}














